#include "QtPusher.h"
#include <QPainter>
#include "QtSequentialAnimationEffect.h"
#include "QtTranslateToEffect.h"

QtPusher::QtPusher(const Direction& direction, QtSprite *parent): QtCellSprite(parent), duration(500), pushDirection(direction)
{
	SetResource("foreground", "pusher");

	SetDirection(direction);
}

QtPusher::~QtPusher()
{
}


void QtPusher::SetDirection(const Direction& direction)
{
	pushDirection = direction;

	switch(pushDirection.Type())
	{
		case Direction::NORTH:
			SetAngle(0);
		break;

		case Direction::SOUTH:
			SetAngle(180);
		break;
	
		case Direction::WEST:
			SetAngle(270);
		break;
	
		case Direction::EAST:
			SetAngle(90);
		break;
	}
}

void QtPusher::BackgroundUpdated()
{
	SetCenterPoint(QPointF(Background()->Width()/2, Background()->Height()/2));

	pushPoint = QPointF(Background()->Width()/2, Background()->Height()/3);
}

void QtPusher::Push()
{
	QtSequentialAnimationEffect seq;

	QtTranslateToEffect effect;

	effect.SetDuration(duration/2);
	effect.SetTarget(this);
	effect.SetEndPosition(pushPoint);

	seq.AddEffect(&effect);

	effect.SetDuration(duration);
	effect.SetTarget(this);
	effect.SetEndPosition(CenterPoint());

	seq.AddEffect(&effect);

	AddEffect(&seq);
	Start();
}







